version 13.1
log using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.log", replace
#delimit ;


*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      sentiment.do                                    *;
*       Date:           January 10, 2019                                *;
*       Author:         MRG/CC                                          *;
*       Purpose:      	Data analysis replication file for It's Not     *;
*                       Only What You Say, It's Also How You Say It:    *;
*                       The Strategic Use Of Campaign Sentiment.        *;
*                       Journal of Politics. Forthcoming                *;
* 	    Input File:     sentiment.dta                                   *;
*       Output File:    sentiment.log                                   *;
*       Data Output:    none                                            *;             
*       Previous file:  sentiment.dta                                   *;
*       Machine:        desktop/laptop                     				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*        Load data                                                      *;
*     ****************************************************************  *;

use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

set more off;

*     ****************************************************************  *;
*       Generate additional variables that are needed for our analysis. *;
*     ****************************************************************  *;

gen incumbent_inflation_l = incumbent*inflation_l;
label var incumbent_inflation "incumbent*inflation_l";

gen incumbent_unemployment_l = incumbent*unemployment_l;
label var incumbent_unemployment_l "incumbent*unemployment_l";

gen incumbent_lrgpde_growth = incumbent*lrgdpe_growth;
label var incumbent_lrgpde_growth "incumbent*lrgpde_growth";

gen incumbent_lrgpdo_growth = incumbent*lrgdpo_growth;
label var incumbent_lrgpdo_growth "incumbent*lrgpdo_growth";

gen incumbent_pm = incumbent*pm;
label var incumbent_pm "incumbent*pm";

gen incumbent_fm = incumbent*fm;
label var incumbent_fm "incumbent*fm";

gen left_right2=left_right*left_right;
label var left_right2 "left_right*left_right";

gen extremist = 0;
replace extremist=1 if family_id ==14 | family_id==40;
replace extremist = . if family_id==.;
label var extremist "1 if communist/socialist or far right, 0 otherwise";

gen extremist2 = 0;
replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
replace extremist2 = . if family_id==.;
label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";

desc;

sum;

*     ****************************************************************  *;
*       Mean positive and negative word scores across all manifestos.   *;
*       This is reported in Table 1.                                    *;
*     ****************************************************************  *;

sum  positive_emotion;
sum  negative_emotion;

*     ****************************************************************  *;
*       Mean positive and negative word scores in English language      *;
*       manifestos.                                                     *;
*     ****************************************************************  *;

sum  positive_emotion if language==2;
sum  negative_emotion if language==2;

*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on language  *;
*     ****************************************************************  *;

xtset language;

xtsum positive_sentiment;

*     ****************************************************************  *;
*       Results in Table 2 - Constant is the average language fixed     *;
*       effect.                                                         *;
*     ****************************************************************  *;

* Model 1 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent, fe;

* Model 2 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm, fe;

* Model 3 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm left_right left_right2, fe;

* Model 4 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist, fe;

* Model 5 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist inflation_l, fe;

* Model 6 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist unemployment_l, fe;

* Model 7 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist lrgdpe_growth, fe;

* Model 8 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist inflation_l incumbent_inflation_l, fe;

* Model 9 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist unemployment_l incumbent_unemployment_l, fe;

* Model 10 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist lrgdpe_growth incumbent_lrgpde_growth, fe;

* Model 11 *;
bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist inflation_l incumbent_inflation_l unemployment_l incumbent_unemployment_l lrgdpe_growth incumbent_lrgpde_growth, fe;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Substantive results on incumbency status via simulation         *;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       incumbent vs opposition - Model 1                               *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent, fe;

preserve;

set obs 10000;

set seed 10101;

drawnorm MG_b1-MG_b2, n(100000) means(e(b)) cov(e(V)) clear;

save simulated_betas, replace;

restore;

merge using simulated_betas;

summarize;

gen incumbent1 = (MG_b2+MG_b1)/(MG_b2);

sum incumbent1;

centile incumbent1, centile(2.5 97.5);

drop MG_b1-MG_b2 incumbent1 _merge;

*     ****************************************************************  *;
*       non-PM incumbent vs opposition - Model 2                        *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm, fe;

preserve;

set obs 100000;

set seed 10101;

drawnorm MG_b1-MG_b3, n(100000) means(e(b)) cov(e(V)) clear;

save simulated_betas, replace;

restore;

merge using simulated_betas;

summarize;

gen non_PM = (MG_b3+MG_b1)/(MG_b3);

sum non_PM;

centile non_PM, centile(2.5 97.5);

*     ****************************************************************  *;
*       PM incumbent vs opposition - Model 2                            *;
*     ****************************************************************  *;

gen PM = (MG_b3+MG_b1+MG_b2)/(MG_b3);

sum PM;

centile PM, centile(2.5 97.5);

*     ****************************************************************  *;
*       PM incumbent vs non_PM incumbent - Model 2                      *;
*     ****************************************************************  *;

gen incumbent_difference = PM-non_PM;

sum incumbent_difference;

centile incumbent_difference, centile(2.5 97.5);

drop MG_b1-MG_b3 PM non_PM incumbent_difference _merge;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Substantive results on policy position via simulation           *;
*       Model 3                                                         *;
*     ****************************************************************  *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm left_right left_right2, fe;

*     ****************************************************************  *;
*       At what level of left-right is positive sentiment maximized?    *;
*       Set marginal effect of left-right equal to 0 and solve.         *;
*     ****************************************************************  *;

di _b[left_right]/(-2*_b[left_right2]);

*     ****************************************************************  *;
*       extremist opposition vs moderate opposition - Model 4           *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist, fe;

preserve;

set obs 100000;

set seed 10101;

drawnorm MG_b1-MG_b4, n(100000) means(e(b)) cov(e(V)) clear;

save simulated_betas, replace;

restore;

merge using simulated_betas;

summarize;

gen extremist_opposition = (MG_b4+MG_b3)/(MG_b4);

sum extremist_opposition;

centile extremist_opposition, centile(2.5 97.5);

drop MG_b1-MG_b4 extremist_opposition _merge;

*     ****************************************************************  *;
*       extremist non-PM incumbent vs moderate non-PM incumbent         *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist, fe;

preserve;

set obs 100000;

set seed 10101;

drawnorm MG_b1-MG_b4, n(100000) means(e(b)) cov(e(V)) clear;

save simulated_betas, replace;

restore;

merge using simulated_betas;

summarize;

gen extremist_nonPM = (MG_b4+MG_b3+MG_b1)/(MG_b4+MG_b1);

sum extremist_nonPM;

centile extremist_nonPM, centile(2.5 97.5);

drop MG_b1-MG_b4 extremist_nonPM _merge;

*     ****************************************************************  *;
*       extremist non-PM incumbent vs moderate non-PM incumbent         *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent incumbent_pm extremist, fe;

preserve;

set obs 100000;

set seed 10101;

drawnorm MG_b1-MG_b4, n(100000) means(e(b)) cov(e(V)) clear;

save simulated_betas, replace;

restore;

merge using simulated_betas;

summarize;

gen extremist_PM = (MG_b4+MG_b3+MG_b1+MG_b2)/(MG_b4+MG_b1+MG_b2);

sum extremist_PM;

centile extremist_PM, centile(2.5 97.5);

drop MG_b1-MG_b4 extremist_PM _merge;

*     ****************************************************************  *;
*       Let's find out the number of times that a party has been an     *;
*       incumbent or an incumbent PM.                                   *;
*     ****************************************************************  *;

sort party_id;

by party_id: egen sum_incumbent=sum(incumbent);

by party_id: egen sum_incumbent_pm=sum(incumbent_pm);

drop if party_id==.;

*     ****************************************************************  *;
*       To help collect summary information about the parties, we'll    *;
*       collapse the data on party_id.                                  *;
*     ****************************************************************  *;

collapse incumbent sum_incumbent incumbent_pm sum_incumbent_pm, by(party_id);

*     ****************************************************************  *;
*       We have manifestos from 108 distinct parties.                   *;
*     ****************************************************************  *;

sum;

*     ****************************************************************  *;
*       74 parties have never been in government. 2 have always been    *;
*       in office. This means that only 32 parties provide variation on *;
*       incumbency status. Of these, only 22 have been incumbents more  *;
*       than once.                                                      *;
*     ****************************************************************  *;

tab sum_incumbent;
tab incumbent;

*     ****************************************************************  *;
*       88 parties have never been PM parties and 2 parties have always *;
*       been pm. This means that only 18 parties provide variation on   *;
*       being an incumbent PM. Of these, only 12 were incumbent PMs     *;
*       more than once.                                                 *;
*     ****************************************************************  *;

tab sum_incumbent_pm;
tab incumbent_pm;

*     ****************************************************************  *;
*       Let's look at incumbency and party fixed effects.               *;
*     ****************************************************************  *;

clear;

use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on party     *;
*     ****************************************************************  *;

xtset party_id;

*     ****************************************************************  *;
*       Estimate the models.                                            *;
*     ****************************************************************  *;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent, fe;

preserve;

set obs 10000;

set seed 10101;

drawnorm MG_b1-MG_b2, n(100000) means(e(b)) cov(e(V)) clear;

save simulated_betas, replace;

restore;

merge using simulated_betas;

summarize;

gen incumbent1 = (MG_b2+MG_b1)/(MG_b2);

sum incumbent1;

centile incumbent1, centile(2.5 97.5);

drop MG_b1-MG_b2 incumbent1 _merge;

*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on language  *;
*     ****************************************************************  *;

xtset language;

*     ****************************************************************  *;
*       Is the effect of incumbency stronger for single-party           *;
*       governments?                                                    *;
*     ****************************************************************  *;

sort election_id;

by election_id: egen incumbent_number = sum(incumbent);

gen coalition=0;

replace coalition=1 if incumbent_number>1;

tab coalition;
 
gen incumbent_coalition = incumbent*coalition;

tab incumbent_coalition;

bootstrap, reps(400) seed(10101) cluster(election_id): xtreg positive_sentiment incumbent coalition incumbent_coalition, fe;

*     ****************************************************************  *;
*       Replication complete                                            *;
*     ****************************************************************  *;

log close;

clear;

